<?php
/**
 * Created by PhpStorm.
 * User: mohuani
 * Date: 2019/4/13
 * Time: 16:54
 */

namespace App\Controllers;


use App\Services\WeatherByCityNameService;

class WeatherInfoByCityNameController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getWeatherByCityName()
    {
        $cityName = isset($_REQUEST['cityName']) ? $_REQUEST['cityName'] : '';

        if ($cityName != '') {
            $weatherByCityNameService = new WeatherByCityNameService();
            $weatherInfo = $weatherByCityNameService->weatherInfoCityName($cityName);

            if (!empty($weatherInfo)) {
                $res = [
                    'status_code' => '0',
                    'status_msg' => '天气信息获取成功',
                    'data' => $weatherInfo,
                ];
            } else {
                $res = [
                    'status_code' => '',
                    'status_msg' => '天气信息失败',
                    'data' => [],
                ];
            }

        } else {
            $res = [
                'status_code' => '',
                'status_msg' => 'cityKey不能为空',
                'data' => [],
            ];
        }

        self::$util->JsonReturn($res);
    }

}